
@inject AuthService AuthService
@inject NavigationManager NavigationManager
@inject LockScreen LockScreenService
@inject LogCacheService LogCacheService
@inject IJSRuntime JSRuntime

<button class="btn btn-link nav-link" @onclick="LogoutAsync">
    <span class="oi oi-account-logout" aria-hidden="true"></span> 退出登录
</button>

@code {
    private async Task LogoutAsync()
    {
        // 在文件顶部已注入 JSRuntime 后，使用注入的实例调用方法
        await JSRuntime.InvokeVoidAsync("localStorage.removeItem", "currentUserId");
        await JSRuntime.InvokeVoidAsync("localStorage.removeItem", "currentUserName");
        await JSRuntime.InvokeVoidAsync("localStorage.removeItem", "currentDisplayName");
        
        await Task.Run(() =>
        {
            // 停止锁屏计时器
            LockScreenService.ClearInactivityTimer();
            
            // 清空日志缓存
            LogWrapper.Clear();
            
            AuthService.Logout();
            
            // 强制跳转到登录界面
            NavigationManager.NavigateTo("/login", true);
        });
    }
}